package com.bnzj.cloud.util;

import com.alibaba.fastjson.JSONObject;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 82653
 */
public class AliyunIdCardUtil {

    private static final String appcode = "3de01d15e7414469a36c7133ff6ca211";
    private static final String host = "https://phonecheck.market.alicloudapi.com";
    private static final String path = "/phoneAuthentication";


    public static Boolean verifyIdCard(String idNo, String name, String phoneNo) {
        String method = "POST";
        Map<String, String> headers = new HashMap<String, String>();
        headers.put("Authorization", "APPCODE " + appcode);
        //根据API的要求，定义相对应的Content-Type
        headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
        Map<String, String> querys = new HashMap<String, String>();
        Map<String, String> bodys = new HashMap<String, String>();
        bodys.put("idNo", idNo);
        bodys.put("name", name);
        bodys.put("phoneNo", phoneNo);

        try {
            HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
            HttpEntity entity = response.getEntity();
            String s = JSONObject.toJSONString(entity);
            JSONObject result = JSONObject.parseObject(s);
//         {"name":"王子宾","idNo":"130821199305011815","phoneNo":"17725598703","respMessage":"身份证信息匹配","respCode":"0000"}
            if ("0000".equals(result.get("respCode"))) {
                return true;
            }
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return false;
    }



}
